<?php


class Login extends CI_Controller {

	public function index(){
        $data['wxapp']=$this->db->get('wxapp')->row_array();
		$this->load->view('login/index',$data);
	}


     public function dologin(){
     	 $post=$this->input->post();
         $post['password']=md5($post['password'].'yw');
         $check=$this->db->where($post)->get('admin')->row_array();
         if ($check) {
          $this->load->library('session');
          $this->session->set_userdata('userinfo',$check);
          
          $data['session_id']=session_id();
          $data['update_time']=time();
          $data['ip']=$_SERVER['REMOTE_ADDR'];
          $this->db->where($post)->update('admin',$data);
       
          echo json_encode(array('code'=>1,'msg'=>'登录成功'));
          exit();
        
         }else {
          echo json_encode(array('code'=>0,'msg'=>'账号或密码错误'));
          exit();
         }
     }


    public function logout(){
    	$this->load->library('session');
    	$this->session->unset_userdata('userinfo');
    		header("Location:/login/index");

    }
    
    public function error(){
    $this->load->library('session');
    $info=$this->session->userdata('userinfo');	
    if(is_null($info)){
    header("Location:/login/index");
    }else{
    $data['userinfo']=$this->db->where('id',$info['id'])->get('admin')->row_array();
    $this->session->unset_userdata('userinfo');
    $this->load->view('/login/error',$data);
     }
    }
}
